package kosta.model.board;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class NewsBoardServiceImpl implements NewsBoardService{
@Resource(name="newsBoardDaoImpl")
private NewsBoardDao newsBoardDao;



@Override
public ListVO getListBoard(String pageNo) throws SQLException {
	if(pageNo==null||pageNo=="") 
		pageNo="1";
	List<BoardVO> list=newsBoardDao.getListBoard(pageNo);
	int total=newsBoardDao.totalContent();
	PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
	ListVO lvo=new ListVO(list,paging);
	return lvo;
}

@Override
public BoardVO  getViewBoard(int no) throws SQLException {
	newsBoardDao.updateCount(no);
	return newsBoardDao.getViewBoard(no);
}

@Override
public void newsWrite(BoardVO vo) {
	newsBoardDao.newsWrite(vo);
}

@Override
public void newsUpdate(BoardVO vo) {
	newsBoardDao.newsUpdate(vo);
}
@Override
public void newsDelete(int no){
	newsBoardDao.newsDelete(no);
}

@Override
public BoardVO showContentNoHit(int no) throws SQLException {
	return newsBoardDao.getViewBoard(no);
}

@Override
public ListVO newsSearchTitle(String text,String pageNo) {
	if(pageNo==null||pageNo=="") 
		pageNo="1";
	HashMap map=new HashMap();
	map.put("text", text);
	map.put("pageNo", pageNo);
	List<BoardVO> list=newsBoardDao.newsSearchTitle(map);
	int total=newsBoardDao.totalContentByTitle(text);
	System.out.println("serImpl totalbytitle "+total);
	PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
	ListVO lvo=new ListVO(list,paging);
	return lvo;

	}

	@Override
	public BoardVO getViewBoard() throws SQLException {
		return newsBoardDao.getViewBoard();
	}
}

